package com.sainbainu.sainbainu

import io.flutter.embedding.android.FlutterActivity

import android.os.Bundle
import android.widget.Toast
import io.flutter.plugin.common.MethodChannel

class MainActivity: FlutterActivity() {
  private val CHANNEL = "com.sainbainu.sainbainu/system_toast"

  override fun onCreate(savedInstanceState: Bundle?) {
      super.onCreate(savedInstanceState)

      MethodChannel(flutterEngine?.dartExecutor?.binaryMessenger, CHANNEL).setMethodCallHandler { call, result ->
          if (call.method == "showToast") {
              val message = call.argument<String>("message")
              showToast(message ?: "No message provided")
              result.success(null)
          } else {
              result.notImplemented()
          }
      }
  }

  // 展示从 Flutter 传递过来的消息
  private fun showToast(message: String) {
      Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
  }
}
